<template>
  <div>
    <el-table :data="tableData"
              border
              style="width: 100%">
      <el-table-column prop="training.trainingname"
                       label="培训名称"
                       width="150">
      </el-table-column>
      <el-table-column prop="training.introduction"
                       label="培训简介">
      </el-table-column>
      <el-table-column label="封面"
                       align="center"
                       width="200">
        <template slot-scope="scope">
          <el-image class="table-td-thumb"
                    :src="scope.row.training.cover"></el-image>
        </template>
      </el-table-column>
      <el-table-column prop="score"
                       label="分数"
                       width="100">
      </el-table-column>
      <el-table-column prop="status"
                       label="状态"
                       width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.status=== '1'">考试已完成</span>
          <span v-if="scope.row.status=== '0'">未学完课程</span>
          <span v-if="scope.row.status=== '2'">未进行考试</span>
          <span v-if="scope.row.status=== '3'">未通过考试</span>
        </template>
      </el-table-column>
      <el-table-column label="操作"
                       width="150">
        <template slot-scope="scope">
          <span v-if="scope.row.status=== '1'"></span>
          <span v-if="scope.row.status=== '0'"></span>
          <span v-if="scope.row.status=== '2'">
            <el-button size="mini"
                       type="success"
                       @click="kaoshi(scope.$index, scope.row)">去考试</el-button>
          </span>
          <span v-if="scope.row.status=== '3'">
            <el-button size="mini"
                       type="success"
                       @click="kaoshi(scope.$index, scope.row)">去重考考试</el-button>
          </span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data () {
    return {
      tableData: [],
      userid: '',
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '添加',
      editForm: {
        perm: "",
        description: "",
        flag: "",
        id: ""
      },
    }
  },
  created () {
    this.getdata()
  },
  inject: ["refresh"],
  methods: {
    getdata () {
      this.userid = localStorage.getItem("id");
      this.$axios.get("/api/exam/findStatus/" + this.userid).then(res => {
        console.log(res);
      })
      this.$axios.get('/api/exam/findAll/' + this.userid).then(res => {
        this.tableData = res.data.data;
      })
    },
    kaoshi: function (index, row) {
      localStorage.setItem('topicid', row.topicid),
       this.$router.push({ path: '/StartExam' });
    },
    closeDialog () {
      this.editFormVisible = false
    }
  }
}
</script>